package blog.com.mw.util;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.MultiPartEmail;

public class EmailUtil {

	 public static Boolean sendEmailAndFile(String eamil,int veriCode) {
	    	// 发送带附件的邮件
			/*
			 * // 附件 EmailAttachment attachment = new EmailAttachment();
			 * attachment.setPath("D:\\TEST\\testEXC.xlsx");
			 * attachment.setDisposition(EmailAttachment.ATTACHMENT);
			 * attachment.setDescription("excel文件"); attachment.setName("MyExcel.xlsx");
			 */
	    	// 邮件
	    	MultiPartEmail simpleEmail = new MultiPartEmail();
	    	simpleEmail.setSSL(true);
	    	simpleEmail.setHostName("smtp.qq.com");
	    	simpleEmail.setAuthentication("1227992942@qq.com", "djomumkzerodjhja");
	    	simpleEmail.setSmtpPort(465);
	    	try {
	    		simpleEmail.setFrom("1227992942@qq.com", "Blog官方", "UTF-8");
				simpleEmail.addTo(eamil);
				simpleEmail.setSubject("Blog账号注册验证码");
		    	simpleEmail.setMsg("您的验证码为："+veriCode+"\n请在5分钟内完成验证！");
//		    	simpleEmail.attach(attachment);附件
		    	simpleEmail.send();
			} catch (EmailException e) {
				e.printStackTrace();
				return false;
			}
	    	return true;
	    }
		/*
		 * public static void main(String[] args) {
		 * System.out.println(sendEmailAndFile()); }
		 */
}
